// pages/goodsDetails/goodsDetails.js
var call = require("../../utils/request.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // imgUrls: [
    //   '../../images/goods2.png',
    //   '../../images/goods2.png',
    //   '../../images/goods2.png'
    // ],
    // indicatorDots: false,
    // autoplay: false,
    // interval: 5000,
    // duration: 1000
    
    imgUrls: [
      { goods_showimg:'/../../images/goods1.png'},
      { goods_showimg:'/../../images/goods2.png'},
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 1000,
    
    goodsTitle:'赣南脐橙500g  大品牌  品质保障',
    price:'16.6',
    oldPrice:'25.6',
    sold:'100',
    inventory:'10',
    deduction:'5',
    many:'15',
    tuDetail:'/../../images/goods2.png',
    theMony: 2,//1-去充值,2-微客币数量
    theMonyNone:"block",//优惠box显示隐藏
    viewShare:'none',//分享弹框显示/隐藏

  },

  //分享给好友
  theShare:function(){
    var that = this;
    that.setData({
      viewShare:'block'
    })
  },

  //取消分享
  cancelShare:function(){
    var that = this;
    that.setData({
      viewShare: 'none'
    })
  },

  //去首页
  toHome:function(){
    wx.reLaunch({
      url: '/pages/home/home'
    })
  },
  //去购物车
  toShoppingCart:function(){
    wx.reLaunch({
      url:"/pages/shoppingCart/shoppingCart"
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var postData = {
      goodsId: 1
    }
    call.request('goods/getGoodsDetail', postData, this.goodsList, this.fail);
  },
  goodsList: function (data) {
    var that = this;
    console.log(data)
    that.setData({
      goodsTitle: data.data[0].name, //商品名称
      price: data.data[0].wkg_price, //微客价
      oldPrice: data.data[0].primary_price, //原价
      sold: data.data[0].saleNum, //已售数量
      inventory: data.data[0].totalNum,//库存
      // tuDetail: , //图文详情
      // imgUrls: data.data[0].image//商品图片（待完善2019-03-12）
    })
  },
  fail: function () {
    console.log("失败")
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})